<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
{literal}
/* popup_box DIV-Styles*/
#popup_box,#popup_box1 { 
	display:none; /* Hide the DIV */
	position:fixed;  
	_position:absolute; /* hack for internet explorer 6 */  
	height:200px;  
	width:320px;  
	background:#FFFFFF;  
	left: 300px;
	top: 50px;
	z-index:100; /* Layering ( on-top of others), if you have lots of layers: I just maximized, you can change it yourself */
	margin-left: 15px;  
	
	/* additional features, can be omitted */
	border:2px solid #ffffff;  	
	padding:15px;  
	font-size:15px;  
	-moz-box-shadow: 0 0 5px #ff0000;
	-webkit-box-shadow: 0 0 5px #ff0000;
	box-shadow: 0 0 10px #123456;
	
}



a{  
cursor: pointer;  
text-decoration:none;  
} 

/* This is for the positioning of the Close Link */
#popupBoxClose {
	font-size:20px;  
	line-height:15px;  
	right:5px;  
	top:5px;  
	position:absolute;  
	color:#6fa5e2;  
	font-weight:500;  	
}
{/literal}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/flexigrid.css" />


<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/flexigrid.js"></script>

<script type="text/javascript">
{literal}

function doClick1()
{
	
	var form1 = document.d2;
	var pid = document.getElementById("orderID").value;
	
	 var itemlist = pid+","+form1.status.value;
	 $.ajax({
		   type: "POST",
		   dataType: "json",
		   url: "?act=order.modify_order",
		   data: "items="+itemlist,
		   success: function(){
		  
			alert("修改成功！");
		    unloadPopupBox('#popup_box1');
		  
		  
		   $("#flex1").flexReload();
		   }
		 });
	
	
	
	
}
function doClick()
{
   var form1 = document.d1;
   /*
   *need to add panduan
   */
   form1.action = '?act=product.add_product';
   form1.submit();
	
	
}
function loadPopupBox(name) 
{	// To Load the Popupbox
	$(name).fadeIn("slow");
		
}

function unloadPopupBox(name) 
{	// TO Unload the Popupbox
	$(name).fadeOut("slow");
	
}
$(document).ready(function(){
	
	$("#flex1").flexigrid
			(
			{
				url: '?act=order.order_list_show',
				dataType: 'json',

			colModel : [
				{display: 'ID', name : 'ID', width : 40, sortable : true, align: 'center'},
				{display: 'CustomerID', name : 'CustomerID', width : 50, sortable : true, align: 'center'},
				{display: 'OrderTime', name : 'OrderTime', width : 150, sortable : true, align: 'left'},
				{display: 'TotalPrice', name : 'TotalPrice', width : 80, sortable : true, align: 'left'},
				{display: 'Receiver', name : 'Receiver', width : 100, sortable : true, align: 'left'},
				{display: 'Phone', name : 'Phone', width : 100, sortable : true, align: 'left'},
				{display: 'Postal', name : 'Postal', width : 100, sortable : true, align: 'left'},
				{display: 'Address', name : 'Address', width : 240, sortable : true, align: 'left'},
				{display: 'OrderState', name : 'OrderState', width : 100, sortable : true, align: 'left'},
				
				
				],
			buttons : [
				{name: 'View', bclass: 'add', onpress : test},
				{name: 'Modify', bclass: 'add', onpress : test},
				{name: 'Export', bclass: 'export', onpress : test}
				],
				searchitems : [
								
								{display: 'ID', name : 'ID', isdefault: true}
								
								],
			sortname: "id",
			sortorder: "asc",
			usepager: true,
			title: '订单信息',
			useRp: true,
			rp: 20,
			nomsg: '没有符合条件的记录存在', 
			showTableToggleBtn: true,
			width: 'auto',
			height: 'auto',
			procmsg: '正在获取数据，请稍候 ...'  
			}
			);   
	
});
function sortAlpha(com)
{ 
    jQuery('#flex1').flexOptions({newp:1, params:[{name:'letter_pressed', value: com},{name:'qtype',value:$('select[name=qtype]').val()}]});
    jQuery("#flex1").flexReload(); 
}

function test(com,grid)
{
    if (com=='Modify')
        {
    	   if($('.trSelected',grid).length>0){
    		   if(confirm('修改订单？')){
    		 
    			 var pid = document.getElementById("orderID");
    			 pid.value = $('.trSelected',grid).find("td").eq(0).text();
    			 loadPopupBox('#popup_box1');
			}
			} else {
				return false;
			} 
        }
    else if (com=='View')
        {
    	  
    	 if($('.trSelected',grid).length==1)
         {
		   
 
			   var pid  = $('.trSelected',grid).find("td").eq(0).text();
			   $.ajax({
				   type: "POST",
				   dataType: "json",
				   url: "?act=order.get_orderItem",
				   data: "items="+pid,
				   success: function(data){
                  
			     if(document.getElementById('dt').childNodes.length>1)
			    	 {
						document.getElementById('dt').removeChild(document.getElementById('dt').childNodes[1]);
			    	 }
				 var table=document.createElement("table");
				   
				
				 for(var i=0;i<data.length;i++)
				   {
				   		var row=table.insertRow();
				   	
				   		var cell=row.insertCell();
						cell.innerText=data[i]['TotalPrice'];
						
						var cell=row.insertCell();
						cell.innerText=data[i]['Amount'];
						
						var cell=row.insertCell();
						
						cell.innerText=data[i]['ProductName'];
						  
				   	    
				   	}	   
				 
					 var row=table.insertRow(); 
					 
					 var cell=row.insertCell();
					     cell.innerText='总价格';
					 
					 var cell=row.insertCell();
					     cell.innerText='数量';
					 
					 var cell=row.insertCell();
					     cell.innerText='书名';
				   
                   var div =document.getElementById('dt');
				   div.appendChild(table);
				   loadPopupBox('#popup_box'); 
				   
				   }
				 });
			   
			      	
			
			
         }
         else if($(".trSelected").length==0){  
              alert("请选择一个您要查看的订单");  
          }  
         else if($(".trSelected").length>1){  
             alert("请每次查看单个订单");  
         }  
      }
    else if (com=='Export')
	{
		window.open("?act=order.export_order");
	}
    	
    	
           
        }            
 
{/literal}
</script>
<title>Insert title here</title>
</head>
<body>
<div>
<table id="flex1" style="display:none"></table>
</div>
<div id="popup_box">	<!-- OUR PopupBox DIV-->
	<h1>详单信息</h1>
	
<div id="dt">
</div>
<br>
<br>	
	
	<a id="popupBoxClose" onClick="unloadPopupBox('#popup_box')">Close</a>	
</div>


<div id="popup_box1">	<!-- OUR PopupBox DIV-->
	<h1>更改订单状态？</h1>
	<form name="d2" action="?act=order.modify_order" method='post'>
<table>
<tr><td>
<input type="hidden" id="orderID" value=""/>
</td>
</tr>
<tr><td>
订单状态:
</td>
<td>
<select name="status">
  <option value ="1">1.未发货</option>
  <option value ="2">2.已发货</option>
  <option value ="3">3.已收货</option>
  <option value ="4">4.取消</option>
  
  </select>
</td>
</tr>

</table>
<br>
<br>	
	<input type="button" value="提交" onClick="doClick1();">
	</form>
	<a id="popupBoxClose" onClick="unloadPopupBox('#popup_box1')">Close</a>	
</div>
</body>
</html>